const { resolve } = require('path');
const { CleanWebpackPlugin} = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports={
  mode: 'production', // 模式, production | development
  // 入口文件配置
  entry: './ts/index.ts',
  // 输出配置
  output: {
  // 输出路径
    path:resolve(__dirname, 'dist'),
    publicPath: '/dist',
    filename: 'js/[name]-[contenthash:6].js'
    // filename: 'js/bundle.js'
  },
  module: {
    // 详细loader配置
    rules: [
      {
        test:/\.(js|ts)$/,
        use:'ts-loader',
        include:resolve(__dirname, 'ts'),
        exclude: /node_modules/
      }
    ]
  },
  resolve: {
    // 忽略文件后缀
    extensions: ['.js', '.jsx', '.css', '.ts']
  },
  plugins: [
    new CleanWebpackPlugin(),
    new HtmlWebpackPlugin({
      template: './index.html',
      filename: 'index.html'// 指定输出文件名
    })
  ],
  devServer:{
    host:'localhost',
    port:'5500',
    open:true,
    stats: 'errors-only', 
  }
}